go to previous page   go to home page   go to next page

Answer:

Exceptions may be thrown when the files are opened.


Opening the Files

DataInputStream  instr;
DataOutputStream outstr;
. . . . 
try
{
  instr = 
    new DataInputStream(
      new BufferedInputStream(
        new FileInputStream( args[0] )));
  
  outstr = 
    new DataOutputStream(
      new BufferedOutputStream(
        new FileOutputStream( args[2] )));
  
  try
  {
    int data;
    while ( true )
    {
      data = instr.readUnsignedByte() ;
      outstr.writeByte( data ) ;
    }
  }
  
  catch ( EOFException  eof )
  {
    outstr.close();
    instr.close();
    return;
  }
  

}


The constructors for FileInputStream and for FileOutputStream throw exceptions which need to be caught. This calls for an outer try{} block.

The outer try{} block encloses the constructors and the I/O loop.


QUESTION 19:

What might go wrong inside the outer try{} block which would cause an exception?